package com.dxy.multids.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dxy.multids.pojo.TaskInfo;
import com.dxy.multids.service.TaskInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/multids/task")
public class TaskInfoController {

    @Autowired
    private TaskInfoService taskInfoService;

    @GetMapping("/getByTaskNo")
    public List<TaskInfo> getByTaskNo(String taskNo) {
        return taskInfoService.list(new LambdaQueryWrapper<TaskInfo>()
                .eq(StrUtil.isNotBlank(taskNo), TaskInfo::getTaskNo, taskNo)
                .orderByDesc(TaskInfo::getCreateTime));
    }

    @GetMapping("/getByPage")
    public IPage<TaskInfo> getByPage(Long pageNum, Long pageSize) {
        if (pageNum == null || pageNum <= 0) {
            pageNum = 1L;
        }
        if (pageSize == null || pageSize <= 0) {
            pageSize = 10L;
        }
        IPage<TaskInfo> page = new Page<>(pageNum, pageSize);
        return taskInfoService.page(page,
                new LambdaQueryWrapper<TaskInfo>().orderByDesc(TaskInfo::getCreateTime));
    }
}
